﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace shuju_jiange
{
    public partial class FrmValueSetting : Form
    {
        private const string strValueSettingFileName = "ValueSetting.dat";
        public FrmValueSetting()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            List<string> strSumItems = new List<string>();
            if (chbA.Checked)
            {
                strSumItems.Add("A");
            }
            if (chbB.Checked)
            {
                strSumItems.Add("B");
            }
            if (chbH.Checked)
            {
                strSumItems.Add("H");
            }

            if (chbAAC2.Checked)
            {
                strSumItems.Add("AAC2");
            }
            if (chbABG2.Checked)
            {
                strSumItems.Add("ABG2");
            }
            if (chbACH2.Checked)
            {
                strSumItems.Add("ACH2");
            }

            if (chbBAC2.Checked)
            {
                strSumItems.Add("BAC2");
            }
            if (chbBGH2.Checked)
            {
                strSumItems.Add("BGH2");
            }
            if (chbBBG2.Checked)
            {
                strSumItems.Add("BBG2");
            }
            if (chbChishucha.Checked)
            {
                strSumItems.Add("次数差");
            }

            if (this.chbA1.Checked) strSumItems.Add("A1");
            if (this.chbA2.Checked) strSumItems.Add("A2");
            if (this.chbA3.Checked) strSumItems.Add("A3");
            if (this.chbA4.Checked) strSumItems.Add("A4");
            if (this.chbA5.Checked) strSumItems.Add("A5");
            if (this.chbA6.Checked) strSumItems.Add("A6");
            if (this.chbB1.Checked) strSumItems.Add("B1");
            if (this.chbB2.Checked) strSumItems.Add("B2");
            if (this.chbB3.Checked) strSumItems.Add("B3");
            if (this.chbB4.Checked) strSumItems.Add("B4");
            if (this.chbB5.Checked) strSumItems.Add("B5");
            if (this.chbB6.Checked) strSumItems.Add("B6");



            if (strSumItems.Count > 0)
            {
                lbValues.Items.Add(string.Join(" ",strSumItems));
            }
        }

        private void btnDelSelection_Click(object sender, EventArgs e)
        {
            object[] selObjects = new object[lbValues.SelectedItems.Count];
            lbValues.SelectedItems.CopyTo(selObjects, 0);
            foreach (object item in selObjects)
            {
                lbValues.Items.Remove(item);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string strValueSettingFilePath = Application.StartupPath + "//" + strValueSettingFileName;

            try
            {
                if (File.Exists(strValueSettingFilePath))
                {
                    File.Delete(strValueSettingFilePath);
                }
                List<string> strs = new List<string>();
                foreach (object item in lbValues.Items)
                {
                    strs.Add(item.ToString());
                }
                File.WriteAllLines(strValueSettingFilePath, strs);
                DialogResult = DialogResult.OK;
                this.Close();
            }
            catch
            {
                MessageBox.Show("文件保存失败。", "提示");
            }
        }

        private void FrmValueSetting_Load(object sender, EventArgs e)
        {
            // 加载值相加数据
            LoadrValueSetting();
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            lbValues.Items.Clear();
            LoadrValueSetting();
        }
        /// <summary>
        /// 加载值相加数据
        /// </summary>
        private void LoadrValueSetting()
        {
            string strValueSettingFilePath = Application.StartupPath + "//" + strValueSettingFileName;
            if (File.Exists(strValueSettingFilePath))
            {
                try
                {
                    string[] strValueSettings = File.ReadAllLines(strValueSettingFilePath);
                    lbValues.Items.AddRange(strValueSettings);
                }
                finally
                {

                }
            }
        }
    }
}
